import { getAgencyBalanceInfoApi } from "@/api/financialManagement/payableManagement/agencyBalance";
import { Ref, ref } from "vue";

export default function InitHook(state: { passData: Ref<AgencyBalance.ListRows> }) {
  const { passData } = state;
  const loading = ref<boolean>(false);
  const tableData = ref<Array<AgencyBalance.AgencyBalanceInfo>>([]);
  const init = () => {
    loading.value = true;
    return getAgencyBalanceInfoApi(passData.value.agentId)
      .then((res: any) => {
        const { code, data } = res;
        if (code === 200) {
          tableData.value = data || [];
        }
      })
      .finally(() => (loading.value = false));
  };
  return {
    tableData,
    init,
    loading
  };
}
